import {
  CallHandler,
  ExecutionContext,
  Injectable,
  NestInterceptor,
} from '@nestjs/common';
import { map } from 'rxjs/operators';
import { Observable } from 'rxjs';

@Injectable()
export class TransformInterceptor implements NestInterceptor {
  intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
    const req = context.switchToHttp().getRequest();
    if (req.url.includes('VerifySession')) {
      return next.handle();
    }
    return next.handle().pipe(
      map((data) => {
        return {
          data,
          code: 200,
          message: '操作成功',
        };
      }),
    );
  }
}
